    var layout_opts = {
		//	reference only - these options are NOT required because are already the 'default'
			closable:				true	// pane can open & close
		,	resizable:				true	// when open, pane can be resized 
		,	slidable:				true	// when closed, pane can 'slide' open over other panes - closes on mouse-out
        ,   paneClass: 'ui-layout-pane'
		,	north__slidable:		false	// OVERRIDE the pane-default of 'slidable=true'
        ,   north__spacing_open :    0
        ,   north__closable:    false
        ,   north__size:        55
        ,   north__showOverflowOnHover:	true
		,   west__spacing_open: 0
        ,   west__spacing_closed: 15
        ,	west__minSize:		100
        ,   west__size:         200
        ,   north__paneSelector:    '#north-wrap'
        ,   west__paneSelector:     '#west-wrap'
        ,   east__paneSelector:     '#east-wrap'
        ,   center__paneSelector:   '#center-wrap'
        ,   center__paneClass:      'ui-layout-pane'
        ,   south__paneSelector:    '#south-wrap'
    };
var global = {};
jQuery(function($) {
    //set layout
    global.layout = $('#out-wrap').layout(layout_opts);
    
    //set tabs
    ubi.tabs.init('#tabs', '#tabs-nav');
    
    //nicedit
    global.niced = new nicEditor({
        iconsPath : '/imgs/niced-icons.gif', 
        buttonList:['bold', 'italic', 'underline', 'strikethrough',
                    'left', 'center', 'right', 'ol','ul',
                    'subscript', 'superscript',
                    'forecolor', 'bgcolor',
                    'fontSize', 'fontFormat',
                    'link', 'citelink','image', 'removeformat',
                    'xhtml']}
    );
    global.niced.setPanel('edit-panel');
    //some event binding
    //search btn on click
    $('#search-btn').click (function () {
        var query_text = $('#search-box').attr('value');
        if (query_text == '')
            return
        search_view.open(query_text);
    })
    
    //search box on keypress
    $('#search-box').keypress(function (event) {
        if (event.keyCode != 13) {
            return true;
        }
        var query_text = $('#search-box').attr('value');
        if (query_text == '')
            return
        search_view.open(query_text);
    });

    $('#note-view-save-btn').click (function () {
        global.open_notes[global.crr_note_id].save_status();
    });

    $('#block-new-btn').click(function () {
        global.open_notes[global.crr_note_id].add_block('');
    });
    $('#more-actions-btn').click (function() {
        more_actions_menu.toggle(); 
    }).hover(function () {
        more_actions_menu.show();
    }, function () {
        more_actions_menu.hide();
    })
    
    var separator = new ubi_menu_item('','',true)
    var more_actions_menu = new ubi_menu('#more-actions-menu');
    more_actions_menu
        .append(new ubi_menu_item('fold', 'Fold Selection')) // 0
        .append(new ubi_menu_item('unfold', 'Unfold Selection')) //1
        .append(separator) // 2
        .append(new ubi_menu_item('select-all', 'Select All')) //3
        .append(new ubi_menu_item('disselect-all', 'Disselect All')) // 4
        .append(new ubi_menu_item('invert-selection', 'Invert Selection')) //5
        .append(separator)//6
        .append(new ubi_menu_item('cut', 'Cut'))//7
        .append(new ubi_menu_item('copy', 'Copy'))//8
        .append(new ubi_menu_item('paste', 'Paste'))//9
        .append(separator)//10
        .append(new ubi_menu_item('mass-add-tags', 'Mass Add Tags'))//11
        .append(new ubi_menu_item('delete-selection', 'Delete Selection')); //12
    more_actions_menu.write();
    more_actions_menu
        .click(0, function () {
            global.open_notes[global.crr_note_id].fold_select();  
        })
        .click(1, function () {
            global.open_notes[global.crr_note_id].unfold_select();  
        })
        .click(3, function () {
            global.open_notes[global.crr_note_id].select_all();  
        })
        .click(4, function () {
            global.open_notes[global.crr_note_id].disselect_all();  
        })
        .click(5, function () {
            global.open_notes[global.crr_note_id].invert_selection();  
        })
        .click(12, function () {
            global.open_notes[global.crr_note_id].remove_select();  
        })


    more_actions_menu.disable(7).disable(8).disable(9);


    $('#filter-box').keypress(function (event) {
        if (event.keyCode != 13) {
            return true;
        }
        var filter_text = $('#filter-box').attr('value');
        if (global.filter_fn)
            global.filter_fn(filter_text);
    }).focus(function () {
        if ($(this).attr('value') == global.filter_default_str) 
            $(this).attr('value', '');
    }).blur(function () {
        if ($(this).attr('value').length == 0) 
            $(this).attr('value', global.filter_default_str);
    }).load(function () {
        $(this).attr('value', global.filter_default_str);
    });

    $('#filter-clear-btn').click(function(){
        $('#filter-box').attr('value', '');
        if (global.filter_fn)
            global.filter_fn('');
    });
    
    $(window).click(
        function (){
            if ($('#note-item-title-replacement').length!=0) {
                var value = $('#note-item-title-replacement').attr('value');
                var id = $($('#note-item-title-replacement')
                    .parents('.note-item')[0]).attr('id').toString().split('_')[0];
                ubi.notebook_view.rename_note(id, value)
            }
    });
    global.dialog = new ubi_dialog(1);
    global.open_notes = {}
    //update_block_list_do(0);
    ubi.notebook_view.init();
    switch_toolbar('#notebook-view-bar', true);
    ubi.tabs.select('#notebook-view');
    key_shortcut.bind_keys(); 

    //init
    global.crr_note_id = -1;
    global.crr_note_title = '';
    global.crr_page = 0;
    global.crr_block_id = -1;
    global.note_status = 0;
    global.filter_default_str = 'type keywords and press ENTER';
    global.options = {}
    global.clipboard = {}
    global.clipboard.data = '';
    global.clipboard.cite_link = function (data) {
        if (data)
            return global.clipboard.data = data;
        else
            return global.clipboard.data;
    }
});


